import myApi from '@/servers/Api';
import { getData } from '@/servers/Http';
import { setDocLogo, setDocTitle } from '@/utils';

const IndexModel = {
  namespace: 'index',
  state: {
    siteConfig: {},
  },
  effects: {
    *getSiteConfig({ payload }, { call, put }) {
      let res = yield getData(myApi.siteConfig);
      let params = {
        siteConfig: res && res.data,
      };
      setDocLogo(res ? res.data.config['wap_logo'] : '');
      setDocTitle(res ? res.data['name'] : '');
      yield put({ type: 'setConfig', payload: params });
    },
  },
  reducers: {
    setConfig(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
  subscriptions: {
    // setup({dispatch, history}) {
    //   return history.listen(({pathname}) => {
    //     if (pathname === '/') {
    //       dispatch({
    //         type: 'query',
    //       });
    //     }
    //   });
    // },
  },
};
export default IndexModel;
